package gui;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Rectangle2D;

/**
 * Created with IntelliJ IDEA.
 * User: Eliseo
 * Date: 06.11.13
 * Time: 22:11
 */
public abstract class Schlaeger extends Rectangle2D.Double implements KeyListener {

    Graphics2D g2d;


    protected static int HOEHE_DES_SCHLAEGERS = 100;
    protected static int BREITE_DES_SCHLAEGERS = 10;

   //int x = 0;
    //int y = 0;
    int panelSizeWidth;
    int panelSizeHeight;

    protected Rectangle eigentlicehrSChlager;

    protected boolean upRIGHT;
    protected boolean downRIGHT;
    protected boolean upLEFT;
    protected boolean downLEFT;

    protected int speed = 5;

    public Schlaeger(int width, int height) {
        panelSizeWidth = width;
        panelSizeHeight = height;
        y = (height / 2) - (HOEHE_DES_SCHLAEGERS / 2);
    }

    /**
     * Die 2 folgende Methoden verschieben den Schläger nach oben und unten
     * es wird auch geprüft das die Schläger nicht über den Rand fliegen.
     */
    public void moveVerticalUP() {
        if (!(y <= 10)) {
            y = getY();
            setY(y -= speed);
        }

    }

    public void moveVerticalDOWN() {
        if (y < (panelSizeHeight - HOEHE_DES_SCHLAEGERS - 10)) {
            y = getY();
            setY(y += speed);
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {

        if (e.getKeyCode() == KeyEvent.VK_UP) {
            upRIGHT = true;
        }
        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            downRIGHT = true;
        }
        if (e.getKeyCode() == KeyEvent.VK_W) {
           upLEFT = true;
        }
        if(e.getKeyCode() == KeyEvent.VK_S){
            downLEFT = true;
        }

    }

    @Override
    public void keyReleased(KeyEvent e) {

        if (e.getKeyCode() == KeyEvent.VK_UP) {
            upRIGHT = false;
        }
        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            downRIGHT = false;
        }
        if (e.getKeyCode() == KeyEvent.VK_W) {
            upLEFT = false;
        }
        if(e.getKeyCode() == KeyEvent.VK_S){
            downLEFT = false;
        }
    }

    public boolean isUpRIGHT() {
        return upRIGHT;
    }

    public void setUpRIGHT(boolean upRIGHT) {
        this.upRIGHT = upRIGHT;
    }

    public boolean isDownRIGHT() {
        return downRIGHT;
    }

    public void setDownRIGHT(boolean downRIGHT) {
        this.downRIGHT = downRIGHT;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }



    protected void setX(int x) {
        this.x = x;
    }



    protected void setY(double y) {
        this.y = y;
    }

    public boolean isUpLEFT() {
        return upLEFT;
    }

    public void setUpLEFT(boolean upLEFT) {
        this.upLEFT = upLEFT;
    }

    public boolean isDownLEFT() {
        return downLEFT;
    }

    public void setDownLEFT(boolean downLEFT) {
        this.downLEFT = downLEFT;
    }

    public int getPanelSizeWidth() {
        return panelSizeWidth;
    }

    public void setPanelSizeWidth(int panelSizeWidth) {
        this.panelSizeWidth = panelSizeWidth;
    }

    public int getPanelSizeHeight() {
        return panelSizeHeight;
    }

    public void setPanelSizeHeight(int panelSizeHeight) {
        this.panelSizeHeight = panelSizeHeight;
    }
}
